Repository navigation
fix(daemon): cancel artifact preparation and refresh failed builds - #4175
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Validation and regression evidence for Base: Same focused command for base, fixed source, and each isolated mutation: pnpm exec vitest run --project unit-core \
packages/daemon/src/resources/artifact-tracking.test.ts \
packages/daemon/src/server/downloadable-artifact-http.test.ts \
packages/daemon/src/server/__tests__/request-diagnostics-http.test.ts \
packages/daemon/src/server/__tests__/http-server-artifacts.test.ts \
packages/daemon/src/server/http/daemon-runtime-artifacts.test.ts
The replacement client-abort test waits for source-stat admission and server-side response close. It observes the tar signal, validates the surviving archive contents/length, and counts actual file streams. It does not spy on The dead post-tar cleanup condition was removed. Sentinel thread r4441374093 remains out of scope: registration describes the source's current owner. All mutations ran sequentially in one disposable checkout outside app-managed worktrees. That checkout was removed. The implementation checkout was not mutated by the experiments. Test patch SHA-256: A cold read of the full diff found no additional issue. No independent sub-agent review was started because this is the implementation sub-agent; Sentinel and Cubic review results are handled below. These edits change artifact HTTP/resource ownership, not device dispatch, capture, interaction, app lifecycle, or native execution. The first exact-head run Live probe at the same production source (Node strip-types, real daemon HTTP server and subprocess runner, an executable tar wrapper that pauses before exec): closed the sole client while preparation was pending; observed the process exited, its archive directory disappeared, and the source remained. A new HTTP download returned 200 with 1,049,363 compressed bytes, its Content-Length matched, the decompressed 1 MiB payload matched, and the source was removed after completion. Probe-owned server, processes and files were cleaned up. No device/session was opened. Cold review also exercised ordinary tar failure while the original opener was settling. The initial abort-only guard still handed that rejected promise to a new waiter (1 failed, 13 passed in the resource suite). Requiring the shared controller to exist and remain un-aborted fixes both terminal states. The final regressions were repeated on the unchanged base and with individual mutations as counted above. Before/after status and patch snapshots of the implementation checkout matched during the experiments. A passed intermediate receipt Final foreground gate: Final receipt counts: 17,006 unit tests passed, 1 skipped; 304 related tests passed. These counts come from the receipt, rather than selection estimates. Repeated the live probe at the pushed head Publication status: the remote PR head matches the exact-head receipt. Sentinel and Cubic are in progress; neither has posted review findings or threads yet. Hosted CI is also in progress and is not claimed passed. |
Size Report
Startup median (7 runs, lower is better):
|
There was a problem hiding this comment.
All reported issues were addressed across 9 files
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
Apex SentinelVerdict: Since the last review: 3 new · 1 still open · 5 no longer raised 4 finding(s): 2 minor, 2 nit. Verdict: approve. 🟡 Minor (2)
🔵 Nit (2)
Reply under an inline comment with Earlier reviewsReview of
|
| Where | Finding |
|---|---|
packages/daemon/src/resources/artifact-tracking.ts:425 |
🆕 A cancelled last waiter can leave a stale directoryArchive in an entry still in the registry |
packages/daemon/src/resources/artifact-tracking.ts:489 |
🆕 HTTP disconnect no longer aborts an in-flight tar: requestArtifactCleanup dropped the abort of the shared archive build |
🔵 Nit (4)
| Where | Finding |
|---|---|
packages/daemon/src/server/http/http-server.ts:457 |
🆕 Removed comment left no replacement for the disconnect-vs-normal-close rule |
packages/daemon/src/resources/artifact-tracking.ts:186 |
🆕 Duplicate already-aborted guard in openDownloadableArtifact is unreachable |
packages/daemon/src/resources/artifact-tracking.ts:348 |
🆕 A cached directoryArchive whose temporary archive is missing is never invalidated, so every later download keeps failing |
packages/daemon/src/server/request-diagnostics-http.ts:155 |
🆕 failStreamedHttpResponse answers a client disconnect as 500 for the diagnostics route |
Review of 3d9cacf0 · 02.11.2026 19:03 UTC
Apex Sentinel
Verdict: approve
Since the last review: 0 new · 1 still open · 3 no longer raised
1 finding(s): 1 nit. Verdict: approve.
🔵 Nit (1)
| Where | Finding |
|---|---|
packages/daemon/src/server/downloadable-artifact-http.ts:86 |
The new res.once('close', cancel) fires on a normal successful close too |
Review of 3e079476 · 02.11.2026 18:26 UTC
Apex Sentinel
Verdict: approve
4 finding(s): 1 minor, 3 nit. Verdict: approve.
🟡 Minor (1)
| Where | Finding |
|---|---|
packages/daemon/src/resources/artifact-tracking.ts:338 |
A build aborted just after its tar succeeds can leave a dead archiveAbortController that blocks every later download |
🔵 Nit (3)
| Where | Finding |
|---|---|
packages/daemon/src/resources/artifact-tracking.ts:338 |
The "build still alive" decision in ensureDirectoryArchive is inferred from an unrelated entry field |
packages/daemon/src/resources/artifact-tracking.ts:199 |
cancelArtifactDownload now forwards caller-supplied abort reasons to the client response |
packages/daemon/src/resources/artifact-tracking.ts:199 |
Client cancellation is reported as RESOURCE_EXPIRED (HTTP 404) because signal?.reason is the only reason passed |
There was a problem hiding this comment.
Apex Sentinel: 4 new findings on 3e07947. The verdict and the full list are in the summary comment.
|
Final bot round at All four Cubic findings are fixed: successful response close no longer aborts the pipeline, the #2198 compatibility rationale is preserved, the new diagnostics test has its loopback guard, and the shared-download test waits on HTTP request events instead of source stat counts. Sentinel: the suspected dead-controller blockage was not reproduced. The late-abort test passes on the reviewed artifact-tracking source, and confirms a fresh download and disposal cleanup. The related ownership nit is addressed with one promise/controller build object and identity-checked settlement. Caller abort reasons are normalized to the existing typed Regression proof in disposable checkouts (each installed with frozen dependencies and built):
Commands: pnpm exec vitest run --project unit-core packages/daemon/src/server/downloadable-artifact-http.test.ts
pnpm exec vitest run --project unit-core packages/daemon/src/resources/artifact-tracking.test.ts packages/daemon/src/server/downloadable-artifact-http.test.ts packages/daemon/src/server/__tests__/request-diagnostics-http.test.ts packages/daemon/src/server/__tests__/http-server-artifacts.test.ts packages/daemon/src/server/http/daemon-runtime-artifacts.test.ts
pnpm exec vitest run --project unit-core test/wire-compat/wire-compat.test.ts test/wire-compat/wire-mutations.test.tsAll mutations were confined to disposable checkouts, before/after implementation snapshots matched, and the disposable checkouts were removed. A cold read of the final diff found no additional issue; no independent sub-agent was started in this implementation sub-agent. The autosquash preserved the final tree; its range-diff was reviewed. Intermediate passed receipt Final foreground gate: Live HTTP probes at this head passed: disconnecting during lone preparation exited the subprocess and removed its temporary archive while preserving the source; retry returned 200 with a complete matching 1 MiB payload (1,049,358 compressed bytes). During a shared preparation, the first client disconnected while tar stayed alive for the second; the survivor returned 200 with matching payload/length (1,049,363 bytes). Both probes observed source removal after completion and cleaned up their servers and owned files. This is the single push for the final bot round. All eight existing review threads have fix commits or evidence-backed dispositions and are resolved. No labels or merge action. New-head hosted CI and automatic bot rechecks remain separate from the local pass. Later nits will receive reasons without another push, as requested. |
There was a problem hiding this comment.
All reported issues were addressed across 6 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 1 file (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
|
The code at 3d9cacf has no blocking problem. The Apple / Smoke Tests check is still running and has not failed. That check drives iOS and macOS commands through the local daemon, and this diff only touches the artifact download route, the diagnostics HTTP error path and artifact tracking, so a failure would likely be unrelated. I read the code paths and did not run tests locally. I also did not check the live lone/shared HTTP probes or the check:affected receipt in the PR body. No conflicts. Not blocking, and fine to take or leave: https://github.com/callstack/agent-device/blob/3d9cacf/packages/daemon/src/resources/artifact-tracking.ts#L235 counts waiters by scanning activeDownloads, but the inventory path (listDownloadableArtifacts -> ensureDirectoryArchive) also joins the same build and is not counted, so a download disconnect during a listing can abort the tar and drop that artifact from the listing. By code trace only, not reproduced. The rule would be: abort the build only when no caller of ensureDirectoryArchive still awaits it. A waiter count on DirectoryArchiveBuild would enforce that. https://github.com/callstack/agent-device/blob/3d9cacf/packages/daemon/src/server/downloadable-artifact-http.ts#L86 is the third inline copy of "abort when res closes before writableFinished" (also in human-control-http.ts and http-server.ts), and this copy already omits the req 'aborted' listener and the typed request_canceled reason. Three mechanisms mark a build as not joinable (https://github.com/callstack/agent-device/blob/3d9cacf/packages/daemon/src/resources/artifact-tracking.ts#L422, the finally in createDirectoryArchive, and the finally in ensureDirectoryArchive). The same-tick "failed" cases in artifact-tracking.test.ts#L88 pin a window the HTTP route cannot reach, while the aborted variants cover a real one. The completion test at downloadable-artifact-http.test.ts#L357 asserts internal pipeline state, and asserting no destroy and no extra release after a 200 would be more observable. The second paragraph of the handleArtifactDownload rationale in test/wire-compat/ledger.json#L261 repeats the "disconnected client receives no new payload" point. Would it be simpler to give DirectoryArchiveBuild { promise, controller, waiters } and make ensureDirectoryArchive(artifactId, entry, hostEnv, signal?) the only code that counts waiters and clears entry.directoryArchiveBuild? Then cancelArtifactDownload only aborts its own controller, and the activeDownloads scan and the abort-on-failure marker go away. One responseDisconnectSignal(req, res) helper in server/http could also replace the three inline detectors. Before merge, the Apple / Smoke Tests run needs to finish green. The earlier inline threads are addressed at this head: cubic-dev-ai's ledger rationale, diagnostics test, request-count gate, writableFinished and failStreamedHttpResponse threads, and the other bot's aborted-build, liveness and request-cancel threads, and they are already resolved: #4175 (comment), #4175 (comment), #4175 (comment), #4175 (comment), #4175 (comment), #4175 (comment), #4175 (comment), #4175 (comment), #4175 (comment). The close-during-final-flush thread does not apply: that close is a real disconnect and nothing reads the outer abort reason, #4175 (comment). |
|
Maintainer review follow-up to the 2026-11-02 review, based on
Same-tick failed-build cases were removed; aborted variants remain, and a real HTTP 500-then-200 test covers retry after tar failure. The completion test observes a valid 200/body, no response destruction and exactly one artifact cleanup before/after expiry/disposal, without pipeline internals. The helper's public signal has separate completed-response coverage. Only the changed Red/green and mutations (sequential disposable checkout, frozen install and build):
The regression command on base was Implementation HEAD/status/patch snapshots were unchanged by the mutations. The disposable checkout was removed. A cold read of the final diff found no additional issue; no independent sub-agent was started in this implementation sub-agent. Final foreground gate: Live HTTP probes at this head: inventory retained one artifact while the overlapping download disconnected and the real tar process stayed alive; the resulting 1 MiB payload downloaded with matching contents/Content-Length (1,049,365 compressed bytes). Lone cancellation exited tar and removed its temporary archive while retaining the source, then retry succeeded (1,049,361 bytes). A shared download survived its peer disconnect (1,049,367 bytes). Source cleanup was observed after the successful downloads, and all probe-owned servers/files were cleaned up. No device/session was opened. This is the single push for this maintainer round. No labels or merge action. Hosted CI (including Apple / Smoke Tests, Coverage and Integration Tests) and automatic bot rechecks are pending at the new head; skipped GitHub-owned/parked local lanes are not claimed passed. Later bot nits receive a reason without another push. |
There was a problem hiding this comment.
All reported issues were addressed across 9 files (changes from recent commits).
Reply with feedback, questions, or to request a fix.
View guided diff | Turn on auto-fix | Re-trigger cubic
There was a problem hiding this comment.
Apex Sentinel: 5 new findings on 47d1ac7. The verdict and the full list are in the summary comment.
|
Inventory cleanup/expiry follow-up at
Same regression command on base plus final tests, fixed source, and isolated mutations: pnpm exec vitest run --project unit-core packages/daemon/src/resources/artifact-tracking.test.ts
The disposable checkout was installed with frozen dependencies and built before the experiment. Before/after HEAD/status/patch state of the implementation was preserved, and the disposable checkout was removed. Expanded focused validation: 99 passed across resource/download, disconnect-helper, human-control, RPC and wire suites (57 functional + 42 wire tests). The ledger expiry sentence is correct again with the restored canonical reason; no ledger/digest edit was required. The missing-cache contract already passes on 47d1ac7 and proves the existing existsSync/rebuild path. The re-raised publication/cancellation interleaving has no await between the post-tar check and publication; existing late-abort coverage remains green, while a completed cache for a live artifact is intentionally reusable. Diagnostics writes nothing from failStreamedHttpResponse after res.destroyed, so its shared HTTP status mapping is retained. Added the finished-response close comment in the helper and removed the redundant caller-abort guard. A cold read of the final diff found no additional issue; no independent sub-agent was started in this implementation sub-agent. Foreground exact-head gate: Live HTTP/subprocess probe: held an inventory-only directory build in a real subprocess tar wrapper, requested cleanup, and observed the source retained until process exit, followed by source/temp archive directory removal. The listing returned This is the single push for this cleanup round. Both Cubic threads and all six requested Sentinel findings have replies with the fix commit or evidence-backed reasons and are resolved. No labels or merge action. New-head hosted CI and bot rechecks are pending; later bot nits receive reasons without another push. |
There was a problem hiding this comment.
Apex Sentinel: 1 new finding on 9e4deae. The verdict and the full list are in the summary comment.
|
The code looks good at 9e4deae. The cancelled-build fix and the inventory cleanup/expiry abort from the earlier review are now in place, and the checks show 21 passing, including Apple / Smoke Tests, which was pending before. There are no conflicts. I did not run any tests, and I did not reproduce your live inventory-only cleanup run or the check:affected receipt. Not blocking, and you can take or leave these: artifact-tracking.ts:346 and Of the earlier inline threads, the inventory abort, the ledger sentence, the cleanup root cause and the redundant abort check are fixed at this commit. These do not apply and are already resolved: listener lifetime, because release() removes the listener; missing cached archive, because the existsSync check falls through to a rebuild; disconnected diagnostics 500, because failStreamedHttpResponse returns early on a destroyed response; and abort reason mix-up, because both signals abort only with the request-canceled error. One low-priority doc-wording thread about the failStreamedHttpResponse comment still applies and does not block. |
Summary
Follow up on #4165: directory archives count inventory and download waiters together, so a client disconnect preserves another caller's build. Cleanup/expiry now aborts an inventory-only build once no active download remains, retaining its source until tar settles and then removing it from inventory.
Share typed HTTP disconnect handling across downloads, human-control and RPC; retain observable completion/retry coverage and the maintainer ledger rationales. Thirteen files changed; scope includes the requested helper consumers. Re-registration ownership is unchanged.
Validation
47d1ac7e0a76b1c35690b0d3b126b6a05257c2a4plus final resource tests: 2 failed/17 passed (cleanup and expiry left tar un-aborted); fixed: 19 passed.9e4deaeb4d816fb00023755c5006295839bee11e: 99 focused tests passed (57 functional + 42 wire). Mutations detect missing abort, wrong expiry reason and stale cache reuse. Live inventory-only cleanup confirms process exit, deferred deletion, empty listing and 404/RESOURCE_EXPIRED.pnpm format,pnpm check:quick, and foreground affected gate passed. Receiptrun-KWPr58: exact commit, unchanged checkout; 17,019 unit passed/1 skipped and 304 related passed.Regression, mutation and live evidence.